<template>
<!-- 因为商品列表组件会在首页用到，会在列表页用到，会在搜索页用到。
     所以封装成一个通用的组件是很好的选择，封装后会大大降低开发难度。 -->
    <div class="goods-info" @click="goGoodsPage()">
        <div class="goods-image">
            <img v-lazy="goodsImage" width="90%" />
        </div>
        <div class="goods-name">{{goodsName}}</div>
        <!-- 钱的格式，filter过滤器 -->
        <div class="goods-price">￥{{goodsPrice | moneyFilter }}</div>
    </div>
</template>

<script>
// 引入filter过滤器
    import {toMoney} from '@/filter/moneyFilter.js'
    export default {
        props:['goodsImage','goodsName','goodsPrice', 'goodsId'],
        filters:{
            moneyFilter(money){
                return toMoney(money)
            }
        },
        methods: {
          goGoodsPage(){
            this.$router.push({name:'Goods', query:{goodsId:this.goodsId}})
          }
        }
    }
</script>

<style scoped>
  .goods-name{
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space:nowrap;
  }
</style>
